public class Test {
    public static void main(String[] args) {

    }

    public boolean evaluateTree(TreeNode root) {
        if(root.val == 1)
            return true;
        else if(root.val == 0)
            return false;

        boolean left = evaluateTree(root.left);
        boolean right = evaluateTree(root.right);
        return root.val == 2 ? left | right : left & right;
    }
}

class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
        this.left = left;
        this.right = right;
      }
}